from peewee import BigIntegerField, BigAutoField, CharField, DateTimeField
from common.model.abstrct import AbstractModel, IntEnumField, AbstractModelWithID
from enums.tenant_user_enum import TenantUserStatusEnum


class TenantUser(AbstractModel):

    class Meta:
        table_name = "tb_tenant_user"
        auto_increment_base = 100_000_000

    user_id = BigAutoField(primary_key=True, help_text="用户id")
    username = CharField(help_text="用户名", null=True)
    first_name = CharField(max_length=64, help_text="姓", null=True)
    last_name = CharField(max_length=64, help_text="名", null=True)
    email = CharField(max_length=64, help_text="邮箱号", null=True)
    phone = CharField(max_length=32, help_text="手机号", null=True)
    avatar = CharField(max_length=255, help_text="头像", null=True)
    alias = CharField(max_length=32, help_text="别名", null=True)
    password = CharField(max_length=128, help_text="密码")
    status = IntEnumField(default=TenantUserStatusEnum.enable, help_text="用户状态", choices=TenantUserStatusEnum)
    last_login = DateTimeField(null=True, help_text="上次登陆时间")


# 租户端用户和租户之间的关系
class MiddleTenantUserForTenant(AbstractModelWithID):

    class Meta:
        table_name = "tb_mid_tenant_user_for_tenant"
        indexes = (
            (("tenant_id", "user_id"), True),
        )

    tenant_id = BigIntegerField(help_text="租户id")
    user_id = BigIntegerField(help_text="用户id")

